package mylittleinvestigations;

import mylittleinvestigations.CaseInformation.CaseXmlWriter;
import mylittleinvestigations.CaseInformation.Case;
import mylittleinvestigations.CaseInformation.CaseXmlReader;
import java.io.IOException;
import java.util.ArrayList;
import org.newdawn.slick.*;
import org.newdawn.slick.geom.*;

public class HiddenForegroundElement extends ForegroundElement
{
    private boolean isBegun;

    public HiddenForegroundElement(String textureId, Vector2 position, Polygon clickPolygon, Conversation conversation, String zoomedViewId, String requiredPartnerId)
    {
        super(textureId, position, 0, null, new ArrayList<ForegroundElementAnimation>(), null, clickPolygon, conversation, zoomedViewId);
        
        this.requiredPartnerId = requiredPartnerId;
        this.isDiscovered = false;
        this.isRequired = false;
        this.isBegun = false;
    }

    public Vector2 getPosition()
    {
        return this.position;
    }
    
    private String requiredPartnerId;
    
    public String getRequiredPartnerId() { return this.requiredPartnerId; }
    private void setRequiredPartnerId(String requiredPartnerId) { this.requiredPartnerId = requiredPartnerId; }
    
    private boolean isDiscovered;
    
    public boolean getIsDiscovered() { return this.isDiscovered; }
    private void setIsDiscovered(boolean isDiscovered) { this.isDiscovered = isDiscovered; }
    
    private boolean isRequired;
    
    public boolean getIsRequired() { return this.isRequired; }
    public void setIsRequired(boolean isRequired) { this.isRequired = isRequired; }
    
    private boolean playerIsInRange;
    
    public boolean getPlayerIsInRange() { return this.playerIsInRange; }
    public void setPlayerIsInRange(boolean playerIsInRange) { this.playerIsInRange = playerIsInRange; }

    public void Begin()
    {
        this.isBegun = true;
    }

    @Override
    public void Update(GameContainer gc, int delta)
    {
        super.Update(gc, delta);

        if (!this.isBegun)
        {
            this.Begin();
        }

        //this.sparkleAnimation.Update(gc, delta);

        if (this.getIsClicked())
        {
            this.setIsDiscovered(true);
        }
    }

    @Override
    public void Draw(GameContainer gc, Graphics g)
    {
        //this.sparkleAnimation.Draw(gc, g, new Vector2(this.position.getX() - 40 / 2, this.position.getY() - 40 / 2), false /* flipHorizontally */, 1 /* scale */);
    }

    public void Draw(GameContainer gc, Graphics g, Vector2 offsetVector)
    {
        //this.sparkleAnimation.Draw(gc, g, new Vector2(this.position.getX() - 40 / 2, this.position.getY() - 40 / 2).subtract(offsetVector), false /* flipHorizontally */, 1 /* scale */);
    }

    @Override
    public void SaveToXml(CaseXmlWriter writer) throws IOException
    {
        writer.StartElement("HiddenForegroundElement");
        
        this.SaveToXmlCore(writer);
        writer.WriteTextElement("RequiredPartnerId", this.requiredPartnerId);
        writer.WriteBooleanElement("IsRequired", this.isRequired);
        
        writer.EndElement();
    }

    HiddenForegroundElement(CaseXmlReader reader)
    {
        reader.StartElement("HiddenForegroundElement");
        
        reader.StartElement("Position");
        this.position = new Vector2(reader);
        reader.EndElement();
        
        this.anchorPosition = reader.ReadIntElement("AnchorPosition");
        
        reader.StartElement("ClickPolygon");
        this.clickPolygon = reader.ReadPolygonElement();
        reader.EndElement();

        if (reader.ElementExists("Encounter"))
        {
            reader.StartElement("Encounter");
            this.encounter = new Encounter(reader);
            reader.EndElement();
        }
        
        reader.EndElement();
    }
}